package
{
	import com.game.manager.ActionManager;
	import com.game.manager.LayerManager;
	import com.interfaces.game.GlobalAPI;
	import com.interfaces.general.data.BindUtil;
	import com.interfaces.general.mangaer.TickManager;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.external.ExternalInterface;
	import flash.system.Security;
	
	[SWF(width="760", height="600", frameRate="40", backgroundColor="#000000")]
	public class Main extends Sprite
	{
		public function Main()
		{
			Security.allowDomain("*");
			
			if(stage) {
				checkExternalInterface();
			} else {
				addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
			}
		}
		
		private function addedToStageHandler(event:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
			checkExternalInterface();
		}
		
		private function checkExternalInterface():void {
			if(ExternalInterface.available) {
				startUP();
			} else {
				addEventListener(Event.ENTER_FRAME, enterFrameHandler);
			}
		}
		
		private function enterFrameHandler(event:Event):void {
			removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
			startUP();
		}
		
		private function startUP():void{
			GlobalAPI.init(this.stage);
			
			//地图
			//人物层
			//ui层
			//tips层
			//鼠标失去焦点层
			
			
			//事件的处理
			//逻辑的处理
			LayerManager.init(this.stage);
			ActionManager.init(this.stage);
			
			gameStart();
		}
		
		private function gameStart():void{
			LayerManager.sceneView.initPlayer();
		}
	}
}